// Definition for singly-linked list.
function ListNode(val, next) {
  this.val = (val === undefined ? 0 : val)
  this.next = (next === undefined ? null : next)
}

function createList(arr) {
  if (arr.length == 0)
    return null;
  let head = new ListNode(arr[0], null),
    headNode = head;
  for (let i = 1; i < arr.length; i++) {
    let temp = new ListNode(arr[i], null);
    head.next = temp;
    head = temp;
  }
  return headNode;
}

function showList(head) {
  while (head) {
    console.log(head.val);
    head = head.next;
  }
}
/**
 * @param {ListNode} head
 * @param {number} m
 * @param {number} n
 * @return {ListNode}
 */
var deleteNodes = function (head, m, n) {
  if (!head || m == 0) return null;
  if (n == 0) return head;

  // head = createList(head);
  let all = m + n,
    count = 1,
    lastN = head,
    nowN = head.next;
  while (nowN) {
    if (count % all >= m) {
      let node = nowN;
      lastN.next = nowN.next;
      nowN = nowN.next;
      delete node;
    } else {
      lastN = nowN;
      nowN = nowN.next;
    }
    count++;
  }
  return head;
};
let head = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
  m = 2,
  n = 3;
console.log(deleteNodes(head, m, n));
head = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], m = 1, n = 3;
console.log(deleteNodes(head, m, n));
head = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], m = 3, n = 1;
console.log(deleteNodes(head, m, n));
head = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], m = 3, n = 1;
